package cn.leelei.spring.Advice;

import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class LoggerConfig {
	private static final Logger LOGGER = Logger.getLogger(String.valueOf(LoggerAdvice.class));

	/**
	 * 定义切点
	 */
	@Pointcut("execution(* cn.leelei.spring.service.impl.IPayByServiceImpl.*(..))")
	public void pointCut() {

	}

	/**
	 * 定义切面
	 */
	@Before(value = "pointCut()")
	public void before() {
		System.out.println("在方法执行之前");

	}

	@After(value = "pointCut()")
	public void after() {
		System.out.println("在方法执行之后");
	}

	/**
	 * 回调函数
	 * 
	 * @param joinPoint
	 * @return
	 * @throws Throwable
	 */
	@Around(value = "pointCut()")
	public Object around(ProceedingJoinPoint joinPoint) {
	
		try {
			Object money = joinPoint.getArgs()[0];
			Object result = joinPoint.proceed();
			LOGGER.debug("支付了" + money + "  结果为：" + result);
			return result;
		} catch (Throwable e) {
			LOGGER.debug("支付失败" + e.getMessage()+"余额不足，请选择支付方式");
		}
		return null;
	}

}
